package com.tjetc.mapper;

import com.tjetc.domain.Vaccination;
import com.tjetc.domain.Vaccine;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

public interface VaccinationMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Vaccination record);

    int insertSelective(Vaccination record);

    Vaccination selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Vaccination record);

    int updateByPrimaryKey(Vaccination record);

    @Select("select * from vaccination where doctor_id=#{id}")
    List<Vaccination> list(int id);

    @Update("update vaccination set jiezhong_time = #{date} where id=#{i}")
    int upd(@Param("i") int i,@Param("date") Date date);

    @Update("UPDATE vaccine SET quantity = quantity - 1 WHERE id = #{id}")
    int decreaseVaccineQuantity(int id);


    @Select("select * from vaccination where newborn_id=#{newbornId} and yimiao_id=#{yimiaoId}")
    List<Vaccination> findBNIYI(@Param("newbornId") Integer newbornId,@Param("yimiaoId") int yimiaoId);

    @Insert("insert into vaccination (newborn_id,yimiao_id,doctor_id) values (#{newbornId},#{yimiaoId},#{doctorId})")
    int set(Vaccination vaccination);


    @Select("select * from vaccination where newborn_id=#{newbornId}")
    List<Vaccination> get(int newbornId);

    int countVaccinationByDoctorId(int id);
     @Select("select count(*) from vaccine where id not in (select yimiao_id from vaccination where newborn_id=#{id} and jiezhong_time is not null)")
    int  countVaccinationNotByNewbornId(int id);//计算还有多少疫苗没有打
    @Select("select * from vaccine where id not in (select yimiao_id from vaccination where newborn_id=#{id} and jiezhong_time is not null)")
    List<Vaccine>  VaccinationNotByNewbornId(int id);//计算还有多少疫苗没有打
}